// 订单相关API
import request from '@/utils/request.js'

/**
 * 创建订单
 * @param {Object} data { productId, num, merchantId }
 */
export const createOrder = (data) => {
  return request({
    url: '/agg/order/create',
    method: 'POST',
    data: data
  })
}

/**
 * 支付订单
 * @param {Object} data { orderId, payAmount, payPointAmount }
 */
export const payOrder = (data) => {
  return request({
    url: '/agg/order/pay',
    method: 'POST',
    data: data
  })
}

/**
 * 获取我的订单列表
 * @param {Object} data { pageIndex, pageSize, statue }
 */
export const getMyOrders = (data) => {
  return request({
    url: '/agg/order/myPage',
    method: 'POST',
    data: data
  })
}

/**
 * 获取我的订单列表（GET方式测试）
 * @param {Object} data { pageIndex, pageSize, statue }
 */
export const getMyOrdersGET = (data) => {
  const params = new URLSearchParams(data).toString()
  return request({
    url: `/agg/order/myPage?${params}`,
    method: 'GET'
  })
}

/**
 * 获取订单详情
 * @param {Number} id 订单ID
 */
export const getOrderDetail = (id) => {
  return request({
    url: `/agg/order/getInfo?id=${id}`,
    method: 'GET'
  })
}
